package k2_oop.p9_collection.demo03;

/**
 * @Author lixinlei
 * @Date 2025/1/20 14:53
 */
public class RedPacketInfo implements Comparable<RedPacketInfo>{

    private String name;
    private double money;
    private String dateTime;

    public RedPacketInfo() {
    }

    public RedPacketInfo(String name, double money, String dateTime) {
        this.name = name;
        this.money = money;
        this.dateTime = dateTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getDateTime() {
        return dateTime;
    }

    public void setDateTime(String dateTime) {
        this.dateTime = dateTime;
    }

    /**
     * 重新equals方法，如果两头对象的name属性相同，就可以判断为相等
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        String name = ((RedPacketInfo)obj).name;
        if(this.name.equals(name)){
            return true;
        }
        return false;
    }

    /**
     * 用于按照金额进行排序
     * @param o the object to be compared.
     * @return
     */
    @Override
    public int compareTo(RedPacketInfo o) {
        double thisMoney = this.money;
        double thatMoney = o.getMoney();
        return thisMoney-thatMoney<0?1:-1;
    }

    @Override
    public String toString() {
        return name + "在 " + dateTime + "抢了 "+ money;
    }
}
